package cn.stylefeng.guns.modular.transport.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.transport.entity.TransportCost;
import cn.stylefeng.guns.modular.transport.model.params.TransportCostParam;
import cn.stylefeng.guns.modular.transport.service.TransportCostService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 运输费用表控制器
 */
@Controller
@RequestMapping("/transportCost")
public class TransportCostController extends BaseController {

    private String PREFIX = "/transport/transportCost";

    @Autowired
    private TransportCostService transportCostService;

    @Autowired
    private UserService userService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/transportCost.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/transportCost_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/transportCost_edit.html";
    }

    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(TransportCostParam transportCostParam) {
        this.transportCostService.add(transportCostParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(TransportCostParam transportCostParam) {
        this.transportCostService.update(transportCostParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(TransportCostParam transportCostParam) {
        this.transportCostService.delete(transportCostParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(TransportCostParam transportCostParam) {
        TransportCost detail = this.transportCostService.getById(transportCostParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(TransportCostParam transportCostParam,String condition ) {
    	User user = userService.getcurrentUser();
    	transportCostParam.setDeliverId(user.getDeliverId());
    	transportCostParam.setDeptId(user.getDeptId());
        return this.transportCostService.findPageBySpec(transportCostParam,condition,user.getOperateId());
    }

}


